package cn.tedu.charging.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayCheckConfiguration {
    //声明2个队列 2个交换机
    @Bean
    public Queue delayCheckQueue(){
        //.map x-message-ttl 60秒 x-dead-leater-exchange x-dead-leater-routing-key
        Map<String,Object> args= new HashMap<>();
        args.put("x-message-ttl",1000*60*5);
        args.put("x-dead-letter-exchange","DELAY_BILL_DL_EX");
        args.put("x-dead-letter-routing-key","DELAY_BILL_DL_RK");
        return QueueBuilder.durable("DELAY_BILL_QUEUE").withArguments(args).build();
    }
    @Bean
    public Queue delayCheckDlQueue(){
        return QueueBuilder.durable("DELAY_BILL_DL_QUEUE").build();
    }
    @Bean
    public Exchange delayCheckExchange(){
        return ExchangeBuilder.fanoutExchange("DELAY_BILL_EX").build();
    }
    @Bean
    public Exchange delayCheckDlExchange(){
        return ExchangeBuilder.directExchange("DELAY_BILL_DL_EX").build();
    }
    //绑定关系
    @Bean
    public Binding delayCheckBinding(){
        return BindingBuilder.bind(delayCheckQueue()).to(delayCheckExchange()).with("").noargs();
    }

    @Bean
    public Binding delayCheckDlBinding(){
        return BindingBuilder.
                bind(delayCheckDlQueue()).to(delayCheckDlExchange())
                .with("DELAY_BILL_DL_RK").noargs();
    }
}
